﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" validateRequest="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>试题库 - 新增题目</title>
    <link type="text/css" href="/Content/common.css" rel="Stylesheet" />
    <style type="text/css">
    .page_center{*position:relative;}/*解决IE6/7下滚动bug */
    .accordion{background:#9dbfe2;color:#111;border-bottom:10px solid #9dbfe2;}
    .accordion_header{height:30px;line-height:30px;padding-left:10px;}
    .accordion_content{margin:0 10px;padding:10px;background:#fff;_zoom:1;
        -moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;
    }
    .accordion_action{margin-top:10px;}
    .in_q{padding:6px 0;margin:2px 0;background:#fff;position:relative;z-index:10;
        border:1px solid #ddd;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;
    }
    .in_q_hover{border-color:#bbb;}
    .in_q_remove_icon{display:none;width:20px;height:20px;overflow:hidden;position:absolute;z-index:11;top:2px;right:2px;cursor:pointer;background:url(/Content/images/icon.png) 0 0 no-repeat;text-indent:-9999px;}
    .in_q_hover .in_q_remove_icon{display:block;}
    .in_q .btn_gray{font-size:12px;}
    .q_row{*zoom:1;}
    .q_row:after{clear:both;content:"\20";display:block;height:0;}
    .q_left{float:left;width:96px;}
    .q_right{margin-left:100px;margin-bottom:10px;}
    .q_right textarea{width:100%;max-width:100%;padding:0;*width:98%;}
    .q_right input[type=text]{width:50%;}
    .q_right input.short{width:120px;}
    </style>
</head>
<body>

<div class="page_container">
	<div class="page_left">
		<div class="page_left_inner">
			<h1 class="left_logo"><span title="试题库系统" class="logo">试题库系统</span></h1>
			<%if (ViewData["userName"] != null){%>
			    <div class="left_message">欢迎您，<br/><%=Html.Encode(ViewData["userName"])%>老师<br /><a href="/Login/Logout/" class="logout">退出</a></div>
			<%} %>
			<ul class="left_nav">
				<li class="current"><a href="/Question/QuestionList">题库管理</a></li>
				<li><a href="/Paper/PaperList/">试卷管理</a></li>
				<li><a href="/Paper/PaperCorrectList1">改卷</a></li>
				<li><a href="/Statistics/PaperList">统计</a></li>
			</ul>
		</div>
	</div>
	<!-- end page_left -->
	<div class="page_center">
		<div class="page_center_inner">
			<div class="tab_container">
				<ul class="tab_nav">
					<li><a href="/Question/QuestionList/">查看题目</a></li>
					<li class="current">添加题目</li>
				</ul>
			</div>
			<!-- end tab_container -->
			<!-- content begin here -->
            <div class="accordion">
			<form action="/Question/QuestionAdd/" method="post" id="question_form">
                <h2 class="accordion_header">题目基本信息</h2>
                <div class="accordion_content" id="content1">
                    <div style="margin-bottom:4px;">
                        <label>题型:</label><%=Html.DropDownList("type", ViewData["type"] as SelectList, "请选择")%>
                        <input type="hidden" name="includeNum" id="includeNum" value="" />
                    </div>
                    <div>
                        <label>语种:</label><%=Html.DropDownList("course", ViewData["course"] as SelectList) %>
                        <label>题目用途:</label><select name="TorE">
                            <option value="考试">考试</option>
                            <option value="练习">练习</option>
                        </select>
                        <label>章节:</label><input type="text" name="chapter" style="width:80px;" class="data_confirm" data-confirm="reHTML length-20"/>
                        <label>知识点:</label><input type="text" name="knowledge" class="data_confirm" data-confirm="reHTML length-50"/>
                    </div>
                    <div class="accordion_action clearfix" id="action1"><a href="#" class="btn_blue right" id="btn_next">下一步</a></div>
                </div>
                <h2 class="accordion_header" id="header2">具体内容...</h2>
                <div class="accordion_content none" id="content2">
                    <div class="" id="ex_question"></div>
                    <div class="" id="in_question"></div>
                    <div class="accordion_action clearfix" id="action2">
                        <a href="#" class="btn_blue right" id="btn_submit">提交题目</a>
                    </div>
                </div>
            </form>
            </div>	
			<!-- content end here -->
			<input type="hidden" id="begin_message" value="<%=TempData["begin_message"] %>"/>
		</div>
	</div>
	<!-- end page_center -->
</div>
<!-- end page_container -->

<script type="text/javascript" src="/Scripts/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/Scripts/common.js"></script>
<script type="text/javascript">
    
    var all_question_template =
    {
        //阅读理解（可以增加小题）
        '阅读理解':
        {
            'main_question': '<label class="q_left">文章：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'choice': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="选择题" />'
                        + '<input type="hidden" class="optionNum" name="inQuestion[_order_].optionNum" value="4" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm short" data-confirm="required choice" /></div>'
                        + '<label class="q_left">答案数目:</label><div class="q_right"><label>单选题<input type="radio" name="inQuestion[_order_].isSingle" value="1" checked="checked" /></label>&nbsp;<label>多选题<input type="radio" name="inQuestion[_order_].isSingle" value="0" /></label></div>'
                        + '<label class="q_left choice_A">选项A:</label><div class="q_right choice_A"><input type="text" name="inQuestion[_order_].option1" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_B">选项B:</label><div class="q_right choice_B"><input type="text" name="inQuestion[_order_].option2" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_C">选项C:</label><div class="q_right choice_C"><input type="text" name="inQuestion[_order_].option3" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_D">选项D:</label><div class="q_right choice_D"><input type="text" name="inQuestion[_order_].option4" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="btn_wrap"><a href="#" class="btn_gray btn_remove btn_space" onclick="removeChoice(this);">删除选项</a><a href="#" class="btn_gray btn_add" data-action="add" onclick="addChoice(this);">增加选项</a></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'fill': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="填空题" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'judge': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="判断题" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><label>正确<input type="radio" value="T" checked="checked" name="inQuestion[_order_].answer" /></label>&nbsp;<label>错误<input type="radio" value="F" name="inQuestion[_order_].answer" /></label></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'qna': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="回答问题" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" class="data_confirm" data-confirm="required reHTML"name="inQuestion[_order_].answer" /></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'in_action': '<div class="left in_action"><a href="#" class="icon_add btn_gray btn_space" data-add="choice">增加选择题</a>'
                        + '<a href="#" class="icon_add btn_gray btn_space" data-add="fill">增加填空题</a>'
                        + '<a href="#" class="icon_add btn_gray btn_space" data-add="judge">增加判断题</a>'
                        + '<a href="#" class="icon_add btn_gray btn_space" data-add="qna">增加问答题</a></div>'
        },
        //完形填空（可以增加小题）
        '完形填空':
        {
            'main_question': '<label class="q_left">文章：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'choice': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="选择题" />'
                        + '<input type="hidden" class="optionNum" name="inQuestion[_order_].optionNum" value="4" />'
                        + '<input type="hidden" name="inQuestion[_order_].isSingle" value="1" />'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm short" data-confirm="required choice" /></div>'
                        + '<label class="q_left choice_A">选项A:</label><div class="q_right choice_A"><input type="text" name="inQuestion[_order_].option1" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_B">选项B:</label><div class="q_right choice_B"><input type="text" name="inQuestion[_order_].option2" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_C">选项C:</label><div class="q_right choice_C"><input type="text" name="inQuestion[_order_].option3" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_D">选项D:</label><div class="q_right choice_D"><input type="text" name="inQuestion[_order_].option4" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="btn_wrap"><a href="#" class="btn_gray btn_remove btn_space" onclick="removeChoice(this);">删除选项</a><a href="#" class="btn_gray btn_add" onclick="addChoice(this);">增加选项</a></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'fill': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="填空题" />'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'in_action': '<div class="left in_action"><a href="#" class="icon_add btn_gray btn_space" data-add="choice">增加选择题</a>'
                        + '<a href="#" class="icon_add btn_gray btn_space" data-add="fill">增加填空题</a></div>'
        },
        //翻译（固定一道小题）
        '翻译':
        {
            'main_question': '<label class="q_left">原文：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'qna': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="回答问题"/>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><textarea name="inQuestion[_order_].answer" class="data_confirm" data-confirm="required reHTML" rows="6"></textarea></div>'
                        + '</div>',
            'pre_insert': 'qna'
        },
        //作文（固定一道小题）
        '作文':
        {
            'main_question': '<label class="q_left">作文要求：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'qna': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="回答问题" />'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><textarea name="inQuestion[_order_].answer" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>'
                        + '</div>',
            'pre_insert': 'qna'
        },
        //综合选择（固定一道小题）
        '综合选择':
        {
            'main_question': '<label class="q_left">题目：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'choice': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="选择题" />'
                        + '<input type="hidden" class="optionNum" name="inQuestion[_order_].optionNum" value="4" />'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm short" data-confirm="required choice" /></div>'
                        + '<label class="q_left">答案数目:</label><div class="q_right"><label>单选题<input type="radio" name="inQuestion[_order_].isSingle" value="1" checked="checked" /></label>&nbsp;<label>多选题<input type="radio" name="inQuestion[_order_].isSingle" value="0" /></label></div>'
                        + '<label class="q_left choice_A">选项A:</label><div class="q_right choice_A"><input type="text" name="inQuestion[_order_].option1" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_B">选项B:</label><div class="q_right choice_B"><input type="text" name="inQuestion[_order_].option2" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_C">选项C:</label><div class="q_right choice_C"><input type="text" name="inQuestion[_order_].option3" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_D">选项D:</label><div class="q_right choice_D"><input type="text" name="inQuestion[_order_].option4" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="btn_wrap"><a href="#" class="btn_gray btn_remove btn_space" onclick="removeChoice(this);">删除选项</a><a href="#" class="btn_gray btn_add" onclick="addChoice(this);">增加选项</a></div>'
                        + '</div>',
            'pre_insert': 'choice'
        },
        //词语搭配（可以增加选择题、填空题）
        '词语搭配':
        {
            'main_question': '<label class="q_left">题干：</label><div class="q_right"><textarea name="content" rows="6" class="data_confirm" data-confirm="required reHTML"></textarea></div>',
            'choice': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="选择题" />'
                        + '<input type="hidden" class="optionNum" name="inQuestion[_order_].optionNum" value="4" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" class="data_confirm short" data-confirm="required choice" /></div>'
                        + '<label class="q_left">答案数目:</label><div class="q_right"><label>单选题<input type="radio" name="inQuestion[_order_].isSingle" value="1" checked="checked" /></label>&nbsp;<label>多选题<input type="radio" name="inQuestion[_order_].isSingle" value="0" /></label></div>'
                        + '<label class="q_left choice_A">选项A:</label><div class="q_right choice_A"><input type="text" name="inQuestion[_order_].option1" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_B">选项B:</label><div class="q_right choice_B"><input type="text" name="inQuestion[_order_].option2" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_C">选项C:</label><div class="q_right choice_C"><input type="text" name="inQuestion[_order_].option3" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left choice_D">选项D:</label><div class="q_right choice_D"><input type="text" name="inQuestion[_order_].option4" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<div class="btn_wrap"><a href="#" class="btn_gray btn_remove btn_space" onclick="removeChoice(this);">删除选项</a><a href="#" class="btn_gray btn_add" onclick="addChoice(this);">增加选项</a></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'fill': '<div class="in_q">'
                        + '<input type="hidden" class="order" name="inQuestion[_order_].Iorder" value="" />'
                        + '<input type="hidden" name="inQuestion[_order_].answerMode" value="填空题" />'
                        + '<label class="q_left">题目：</label><div class="q_right"><input type="text" name="inQuestion[_order_].Icontent" class="data_confirm" data-confirm="required reHTML" /></div>'
                        + '<label class="q_left">参考答案：</label><div class="q_right"><input type="text" name="inQuestion[_order_].answer" /></div>'
                        + '<div class="in_q_remove_icon" title="删除该小题">X</div>'
                        + '</div>',
            'in_action': '<div class="left in_action"><a href="#" class="icon_add btn_gray btn_space" data-add="choice">增加选择题</a>'
                        + '<a href="#" class="icon_add btn_gray btn_space" data-add="fill">增加填空题</a></div>'
        }
    };

    var in_question_num = 0;

    //选择题增加选项
    function addChoice(button) {
        var btn_wrap = $(button).parent('.btn_wrap'),
            choice_wrap = btn_wrap.parent(),
        /*delete  current_num = choice_wrap.attr('data-choicenum');*/
            current_num = choice_wrap.find('.optionNum').val();
        var insert_char;
        (current_num <= 8) && (insert_char = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'][current_num]);

        //插入新选项，在这之前要看一下这是第几道小题
        var option_num = choice_wrap.find('.choice_A input:nth-child(1)').attr('name').replace(/(^.*\[)|(\].*$)/g, '');
        btn_wrap.before('<label class="q_left choice_' + insert_char + '">选项' + insert_char + ':</label><div class="q_right choice_' + insert_char + '"><input type="text" name="inQuestion[' + option_num + '].option' + (++current_num) + '" class="data_confirm" data-confirm="required reHTML" /></div>');
        //更新选项数目
        /*delete choice_wrap.attr('data-choicenum', current_num);*/
        choice_wrap.find('.optionNum').val(current_num);
        //如果已经8个选项，干掉添加按钮
        (current_num >= 8) && btn_wrap.find('.btn_add').remove();
        //如果允许删除，加上删除按钮
        (current_num <= 3) && btn_wrap.prepend('<a href="#" class="btn_gray btn_remove btn_space" onclick="removeChoice(this);">删除选项</a>');
        
        return false;
    }

    //选择题删除选项
    function removeChoice(button) {
        var btn_wrap = $(button).parent('.btn_wrap'),
            choice_wrap = btn_wrap.parent(),
        /*delete current_num = choice_wrap.attr('data-choicenum');*/
        current_num = choice_wrap.find('.optionNum').val();
        var remove_char;
        (current_num <= 8) && (remove_char = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'][--current_num]);

        //删掉最后一个选项
        choice_wrap.find('.choice_' + remove_char).remove();
        //更新选项数目
        /*delete choice_wrap.attr('data-choicenum', current_num);*/
        choice_wrap.find('.optionNum').val(current_num);
        //如果少于2个选项，干掉删除按钮
        (current_num <= 2) && btn_wrap.find('.btn_remove').remove();
        //如果允许添加，加上添加按钮
        (current_num >= 7) && btn_wrap.append('<a href="#" class="btn_gray btn_add" onclick="addChoice(this);">增加选项</a>');
        
        return false;
    }

    //将所有小题的顺序排好
    function order_in_question() {
        var all_in_question = $('#in_question').find('.in_q');
        var j_children, j_child;
        $.each(all_in_question, function(index, in_q) {
        j_children = $(in_q).find('*');
            //所有的表单元素都更新一下name属性
            $.each(j_children, function(child_index, child) {
                j_child = $(child);
                if (j_child.attr('name') != undefined) {
                    j_child.attr('name', j_child.attr('name').replace(/inQuestion\[\d*\]/, 'inQuestion[' + index + ']'));
                }
            });
            //更新题内顺序
            $(in_q).find('.order').val(index + 1);
        });
    }

    //下一步
    function doNext() {
        /*检查第一步选择的题型
         *如果有问题，给出提示信息，退出
         *如果没问题，
         *  取消“下一步”按钮的事件
         *  把第二步的省略号去掉，显示第二步的框和按钮
         *  插入对应的主题干
         *  显示用来插入小题的操作条，注册事件：注册添加小题目的事件
         *  注册事件：再次选择第一步的题型时，给出提示信息，这将改变第二步的题目结构
        */
        //检查第一步选择的题型
        var type_value = $('#type').val();
        if (type_value == '' || type_value == null) {
            message('请先选择题型，再点击下一步', 'error', true, 5000);
            return false;
        }

        //取消“下一步”按钮的事件
        $('#btn_next').unbind('click', doNext);
        
        //把第二步的省略号去掉，显示第二步的框和按钮
        $('#header2').text($('#header2').text().replace('...', ''));
        $('#content2').slideDown(200);

        //获取对应的模板
        var question_template = all_question_template[type_value];
        if (question_template == null) {
            return false;
        }
        //插入主题干
        $('#ex_question').html(question_template.main_question);
        //插入固定的小题
        if (question_template.pre_insert != undefined) {
            var in_q = $(question_template[question_template.pre_insert].replace(/_order_/g, in_question_num++));
            in_q.find('.order').val(in_question_num);
            $('#in_question').append(in_q);
        }
        //插入小题操作条
        if (question_template.in_action != undefined) {
            $('#action2').prepend(question_template.in_action);
            //注册添加小题的事件
            $('#action2').on('click', function(event) {
                var target = $(event.srcElement || event.target);
                var in_question = target.attr('data-add');
                if (in_question == undefined) return false;
                var in_q = $(question_template[in_question].replace(/_order_/g, in_question_num++));
                in_q.find('.order').val(in_question_num);
                $('#in_question').append(in_q);
                return false;
            });
        }
        //注册事件：再次选择第一步的题型时，给出提示信息，这将改变第二步的题目结构
        $('#type').on('change', function() {
            if (confirm("改变题型之后会改变题目的结构，并清空题目，是否继续?")) {
                (question_template.in_action != undefined) && $('#action2').unbind('click');
                $('#type').unbind('change');
                $('#type').on('change', function() {
                    if ($(this).val() == '听力') {
                        message('该题型正在开发中，暂时不可用', 'success', true, 5000);
                        $(this).val('');
                    }
                });
                $('#btn_next').on('click', doNext);
                $('#content2').slideUp(200, function() {
                    $('#ex_question').empty();
                    $('#in_question').empty();
                    $('#action2').find('.in_action').remove();
                });
                in_question_num = 0;
                return true;
            } else {
                $(this).val(type_value);
                return false;
            }
        });
    }

    
    //提交
    function doSubmit() {
        //填写大题包括的小题数目
        $('#includeNum').val($('#in_question').find('.in_q').length);
        //提交之前验证所有填的信息
        if ($('.in_q').length == 0) {
            message('您未添加任何小题目', 'error', true, 5000);
            return false;
        }
        if (isInputOK()) {
            //提交
            document.getElementById('question_form').submit();
        }
    }
    
    //添加新语种
    var course_selector = $('#course');
    if (course_selector.length > 0) {
        course_selector.append('<option value="添加新语种" class="new_course">添加新语种</option>');
        course_selector.on('change', function() {
            var selector = $(this);
            if (selector.val() == '添加新语种') {
                var new_course = prompt('请输入新语种名称', '') || '';
                new_course = replaceAllHTML(new_course);
                if (new_course.length > 0) {
                    $.ajax({
                        type: 'post',
                        url: '/Question/CourseAdd',
                        data: 'newCourse=' + new_course,
                        dataType: 'text',
                        success: function(msg) {
                            if (msg.indexOf('成功') > -1) {
                                message(msg, 'success', true, 5000);
                                selector.find('.new_course').before('<option value="' + new_course + '">' + new_course + '</option>');
                            }
                            else {
                                message(msg, 'error', true, 5000);
                            }
                        },
                        error: function() {
                        }
                    });
                }
                selector.val(selector.find('option').first().val());
            }
        });
    }

    //鼠标移上小题时加class名
    $('#in_question').on('mouseenter', '.in_q', function() {
            $(this).addClass('in_q_hover');
    }).on('mouseleave', '.in_q', function() {
            $(this).removeClass('in_q_hover');
    });

    //点击"X"删除小题
    $('#in_question').on('click', '.in_q_remove_icon', function() {
        $(this).parent('.in_q').remove();
        in_question_num--;
        order_in_question();
    });

    //下一步按钮
    $('#btn_next').on('click', doNext);
    //提交按钮
    $('#btn_submit').on('click', doSubmit);

    //增加系统没有的题型选项
    $('#type').append('<option value="听力">听力</option>');
    $('#type').on('change', function() {
        if ($(this).val() == '听力') {
            message('该题型正在开发中，暂时不可用', 'success', true, 5000);
            $(this).val('');
        }
    });
    
</script>

</body>
</html>
